// JavaScript Document

// Calculate the lat/long you would have traveled 
function calculateProgressLocation(c1,c2, interval)
{
	var latDiff = c2.lat()-c1.lat();
	var lngDiff = c2.lng()-c1.lng();
	
	var lat = c1.lat()+latDiff*interval;
	var lng = c1.lng()+lngDiff*interval;
	
	return new google.maps.LatLng(lat,lng)
	
}

function coordinateDistance(p1,p2)
{
	if(p1==null||p2==null)return 0
	if(p1==undefined||p2==undefined)return 0
	
	var lat1 = p1.lat();
	var lat2 = p2.lat();
	var lon1 = p1.lng();
	var lon2 = p2.lng();
	
	var R = 6371; // km
	var dLat = (lat2-lat1)*(Math.PI/180)
	var dLon = (lon2-lon1)*(Math.PI/180)
	var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
			Math.cos(lat1*(Math.PI/180)) * Math.cos(lat2*(Math.PI/180)) * 
			Math.sin(dLon/2) * Math.sin(dLon/2); 
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
	var d = R * c;
	
	return d
}